package com.peter.demon_03;

import java.io.IOException;
import java.net.MalformedURLException;

import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) {
		WebClient webclient = new WebClient(BrowserVersion.CHROME);
		webclient.getOptions().setJavaScriptEnabled(true);
		webclient.getOptions().setCssEnabled(true);
		webclient.getOptions().setThrowExceptionOnScriptError(false);

		String url = "https://so.gushiwen.org/shiwenv_8bc0871fe00b.aspx";
		String url1 = "https://so.gushiwen.org/shiwen2017/ajaxfanyi.aspx?id=1599";
		try {
			HtmlPage page = webclient.getPage(url);
			DomNodeList<DomNode> lists = page.querySelector(".contyishang").querySelectorAll("p");
			HtmlElement aButton = page.querySelector(".contyishang div a");

			System.out.println(aButton.asXml());

			System.out.println("--------------------------------------------------------------------");

			for (var a : lists) {
				System.out.println(a.asText());
			}

		} catch (FailingHttpStatusCodeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
